package com.joaosavio.example.customer_ws;

import static org.junit.Assert.assertEquals;

import java.io.InputStream;
import java.util.UUID;

import javax.ws.rs.core.Response;

import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxrs.client.WebClient;
import org.junit.BeforeClass;
import org.junit.Test;

public class HelloWorldIT {
	private static String endpointUrl;

	@BeforeClass
	public static void beforeClass() {
		endpointUrl = System.getProperty("service.url");
	}

	@Test
	public void getHelloTest() throws Exception {
		String name = UUID.randomUUID().toString();
		WebClient client = WebClient.create(endpointUrl).path("/hello")
				.query("name", name);
		Response response = client.accept("text/plain").get();
		assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
		String value = IOUtils.toString((InputStream) response.getEntity());
		assertEquals("Hello " + name, value);
	}
}